﻿using Common;
using DataLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using ZXing;
using System.Linq;

namespace TicketSystem
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private BarCode bc = new BarCode();
        private DocumentBase _docement;

        private TicketSystemEntities tse = new TicketSystemEntities();
        PublicMethod pm = new PublicMethod();
        private void btn_bar_Click(object sender, EventArgs e)
        {
            bc.CreateBarCode(picBox, txt_Content.Text);
        }

        private void btn_Qr_Click(object sender, EventArgs e)
        {
            bc.CreateQuickMark(picBox, txt_Content.Text);
        }

        private void btn_Decode_Click(object sender, EventArgs e)
        {
            if (picBox.Image == null)
            {
                MessageBox.Show("请录入图像后在进行解码");
                return;
            }
            BarcodeReader reader = new BarcodeReader();
            Result result = reader.Decode((Bitmap)picBox.Image);
            MessageBox.Show(result.Text);
        }

        //打印
        private void btn_Print_Click(object sender, EventArgs e)
        {
            if (picBox.Image == null)
            {
                MessageBox.Show("首先需要载入一张图片");
                return;
            }
            else
            {
                _docement = new ImageDocument(picBox.Image);
            }
            _docement.showPrintPreviewDialog();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            txt_Content.Text = System.DateTime.Now.ToString("yyyyMMddhhmmss").Substring(0, 12);
            int roleid = tse.Operators.Where(u => u.OperatorID == GetOperator.OperatorID).FirstOrDefault().RoleID;
            List<string> l = new List<string>();
            var right = tse.RoleRights.Where(u => u.RoieID == roleid);
            foreach (var r in right)
            {
                l.Add(r.Rights.RightName);
            }
            //验证操作员是否可以打印和导出导游信息
            pm.CanPrint(this.btn_Print, l);
        }

    }
}
